/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-15 14:14:23
 * @filename : static/logic/nmm/src/views/upgrade.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module){
    var mailDetailView, nav='mailDetail', 
        mId = 'mailDetail',reRender = false,menuName = 'mailDetail',
        tpl = require('{view}mailDetail.tpl'),
        panel = require('{component}panel/zepto.panel'),
        tplN = require('{view}userNav.tpl');

    mailDetailView = Backbone.View.extend({

        el: '',

        template: _.template(tpl),
        templateN: _.template(tplN),


        initialize: function () {},

        render: function (obj) {
            if (share.PMSG == null) {
                window.location.href = '#messageList/whole';
                return;
            }

            if (!share.checkPermission(true)){return;};

            if ($('#'+mId).length < 1) { 
                var id = obj.val;
                var data = JSON.parse($('#messageConversation').find('#'+id).attr('data'));
                data.time = this.formatTime(data.time);
                $('body').append(this.template(data));
            } else {
                var id = obj.val;
                var data = JSON.parse($('#messageConversation').find('#'+id).attr('data'));
                data.time = this.formatTime(data.time);
                $('#'+mId).replaceWith(this.template(data));
                $('#'+mId).css('display','block');
            }
            this.bindEvt();            
            share.panel(panel,this.templateN,mId,menuName);
        },

        formatTime : function(datetime) {
             //datetime = datetime.replace(/-/g,'/');
             datetime = datetime.replace('T',' ');
             datetime = datetime.replace('Z','');
             return datetime;
        },

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);     
          
            dom.find('.back').on('tap',function(e){
                e.stopPropagation();
                window.history.go(-1);
            }); 
        },

        panel: function() {
            panel.run({
                rootDom : $('#'+mId),
                contentDom : $('#'+mId).find('.body_all')
            });
        }

    });
    module.exports = mailDetailView;
});
